package com.cino.demos.controller.mySqlJson;

import com.cino.demos.common.Result;
import com.cino.demos.entity.mysqlJson.UserJson;
import com.cino.demos.entity.mysqlJson.UserJsonQuery;
import com.cino.demos.mapper.mysqlJson.UserJsonMapper;
import com.cino.demos.service.MysqlJsonService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/mysql")
public class MysqlJsonController {

    @Resource private MysqlJsonService mysqlJsonService;

    @Resource private UserJsonMapper userJsonMapper;

    @GetMapping("/getOrg")
    public Result getOrg(){
        return Result.success(userJsonMapper.selectUserOrgById(7L));
    }

    @PostMapping("/like")
    public Result like(@RequestBody UserJsonQuery userJsonQuery){
        return Result.success(userJsonMapper.selectUserLike(userJsonQuery.getLang()));
    }

//---------------单表 增删改查---------------------------------------------------
    @PostMapping("/insert")
    public Result insert(){
        mysqlJsonService.insert();
        return Result.success();
    }

    @GetMapping("/selectUser")
    public Result select(){
        return Result.success(mysqlJsonService.select());
    }

    @PutMapping("/update")
    public Result update(){
        mysqlJsonService.update();
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result delete(){
        mysqlJsonService.delete();
        return Result.success();
    }
// ----------------------------检验返回时能否映射成Map--------------------------------
    @GetMapping("/map")
    public Result Map(){
        UserJson userJson = userJsonMapper.selectUser2Map(7L);
        return Result.success(userJson);
    }
}
